package com.lambda.demo5.demo6;

import java.util.function.Function;

/**
 * @ClassName Test
 * @Description 把字符串"张三,18"转换为学生对象，获取学生对象的年龄，
 * 加1岁后转换为整数
 * @Author Kx
 * @Date 2025/4/2 11:14
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) {
        String str = "张三,18";

        // 把字符串转换为学生对象
        Function<String, Student> function = (str1) ->{
            // 截取姓名和年龄
            String[] strArr = str1.split(",");

            String name = strArr[0];
            int age = Integer.parseInt(strArr[1]);

            return new Student(name, age + 1);
        };

        // 获取学生对象
        Student student = function.apply(str);

        // 把学生年龄转换成整数
        Function<Student, Integer> function1 = (student1) -> {
            return student1.getAge();
        };

        Integer age = function1.apply(student);

        System.out.println(age);
    }
}
